package strategy

// TradeMode 策略模式
type TradeMode int

const (
	//回测
	TradeModeBackTest TradeMode = iota
	//模拟或者测试
	TradeModePaperTrading
	// 实盘
	TradeModeLiveTrading
)

func (t TradeMode) String() string {
	switch t {
	case TradeModeBackTest:
		return "BackTest"
	case TradeModePaperTrading:
		return "PaperTrading"
	case TradeModeLiveTrading:
		return "LiveTrading"
	default:
		return "None"
	}
}

// 回测交易撮合事件类型
const (
	SimEventKey   = "event"
	SimEventOrder = "order" // 委托
	SimEventDeal  = "deal"  // 成交
)

// Direction 委托/持仓方向
type Direction int

const (
	DirectionNone Direction = iota // None
	Buy                            // 开多
	Sell                           // 开空
	CloseBuy                       // 平多
	CloseSell                      // 平空
)

func (d Direction) String() string {
	switch d {
	case Buy:
		return "Buy"
	case Sell:
		return "Sell"
	case CloseBuy:
		return "CloseLong"
	case CloseSell:
		return "CloseShort"
	default:
		return "None"
	}
}

// OrderType 委托类型
type OrderType int

const (
	OrderTypeMarket     OrderType = iota // 市价单
	OrderTypeLimit                       // 限价单
	OrderTypeStopMarket                  // 市价止损单
	OrderTypeStopLimit                   // 限价止损单
)

func (t OrderType) String() string {
	switch t {
	case OrderTypeMarket:
		return "Market"
	case OrderTypeLimit:
		return "Limit"
	case OrderTypeStopMarket:
		return "StopMarket"
	case OrderTypeStopLimit:
		return "StopLimit"
	default:
		return "None"
	}
}

// OrderStatus 委托状态
type OrderStatus int

const (
	OrderStatusCreated         OrderStatus = iota // 创建委托
	OrderStatusRejected                           // 委托被拒绝
	OrderStatusNew                                // 委托待成交
	OrderStatusPartiallyFilled                    // 委托部分成交
	OrderStatusFilled                             // 委托完全成交
	OrderStatusCancelPending                      // 委托取消
	OrderStatusCancelled                          // 委托被取消
	OrderStatusUntriggered                        // 等待触发条件委托单
	OrderStatusTriggered                          // 已触发条件单
	OrderStatusParked                             //预埋单
)

func (s OrderStatus) String() string {
	switch s {
	case OrderStatusCreated:
		return "Created"
	case OrderStatusRejected:
		return "Rejected"
	case OrderStatusNew:
		return "New"
	case OrderStatusPartiallyFilled:
		return "PartiallyFilled"
	case OrderStatusFilled:
		return "Filled"
	case OrderStatusCancelPending:
		return "CancelPending"
	case OrderStatusCancelled:
		return "Cancelled"
	case OrderStatusUntriggered:
		return "Untriggered"
	case OrderStatusTriggered:
		return "Triggered"
	case OrderStatusParked:
		return "Parked"
	default:
		return "None"
	}
}

type IntervalType int

const (
	TICK IntervalType = iota
	SECOND
	MINUTE
	HOUR
	DAY
	WEEK
	MONTH
	QUATER
	YEAR
)

// ContractType 合约类型
const (
	ContractTypeNone = ""   // Non-delivery contract 非交割合约
	ContractTypeW1   = "W1" // week 当周合约
	ContractTypeW2   = "W2" // next week 次周合约
	ContractTypeM1   = "M1" // month 月合约
	ContractTypeQ1   = "Q1" // quarter 季度合约
	ContractTypeQ2   = "Q2" // next quarter 次季度合约
)

// K线周期
const (
	PERIOD_TICK   = "t"
	PERIOD_SECOND = "s"
	PERIOD_MIN    = "m"
	PERIOD_HOUR   = "h"
	PERIOD_DAY    = "D"
	PERIOD_WEEK   = "W"
	PERIOD_MONTH  = "M"
	PERIOD_YEAR   = "Y"
	PERIOD_1MIN   = "1m"
	PERIOD_3MIN   = "3m"
	PERIOD_5MIN   = "5m"
	PERIOD_15MIN  = "15m"
	PERIOD_30MIN  = "30m"
	PERIOD_60MIN  = "60m"
	PERIOD_1H     = "1h"
	PERIOD_2H     = "2h"
	PERIOD_3H     = "3h"
	PERIOD_4H     = "4h"
	PERIOD_6H     = "6h"
	PERIOD_8H     = "8h"
	PERIOD_12H    = "12h"
	PERIOD_1DAY   = "1d"
	PERIOD_3DAY   = "3d"
	PERIOD_1WEEK  = "1w"
	PERIOD_1MONTH = "1M"
	PERIOD_1YEAR  = "1y"
)

type ModeType int

const (
	TickMode = 0
	BarMode  = 1
	Both     = 2
)

func (t ModeType) String() string {
	switch t {
	case TickMode:
		return "Tick"
	case BarMode:
		return "Bar"
	case Both:
		return "Both"
	default:
		return "None"
	}
}

// open close flag type, 开仓、平仓标志
type OpenCloseType int

const (
	OpenFlag  = 1
	CloseFlag = -1
)

func (t OpenCloseType) String() string {
	switch t {
	case OpenFlag:
		return "OpenFlag"
	case CloseFlag:
		return "CloseFlag"
	default:
		return "None"
	}
}

type OffsetType int

const (
	OPEN           OffsetType = 1
	CLOSE          OffsetType = -1
	CLOSETODAY     OffsetType = -2
	CLOSEYESTERDAY OffsetType = -3
)

func (t OffsetType) String() string {
	switch t {
	case OPEN:
		return "Open"
	case CLOSE:
		return "Close"
	case CLOSETODAY:
		return "CloseToday"
	case CLOSEYESTERDAY:
		return "CloseYesterday"
	default:
		return "None"
	}
}
func (t OffsetType) StringCn() string {
	switch t {
	case OPEN:
		return "开仓"
	case CLOSE:
		return "平仓"
	case CLOSETODAY:
		return "平今"
	case CLOSEYESTERDAY:
		return "平昨"
	default:
		return "未知"
	}
}

// 多空标志
type LongShortType int

const (
	LongFlag  = 1
	ShortFlag = -1
)

func (t LongShortType) String() string {
	switch t {
	case LongFlag:
		return "LongFlag"
	case ShortFlag:
		return "ShortFlag"
	default:
		return "None"
	}
}

type DirectType int

const (
	LONG  DirectType = 1
	SHORT DirectType = -1
	BUY   DirectType = 1
	SELL  DirectType = -1
)

func (t DirectType) String() string {
	switch t {
	case LONG | BUY:
		return "Long"
	case SHORT | SELL:
		return "Short"
	default:
		return "None"
	}
}
func (t DirectType) StringCn() string {
	switch t {
	case LONG | BUY:
		return "多头"
	case SHORT | SELL:
		return "空头"
	default:
		return "未知"
	}
}

// 开平多空标志
type OpenCloseLongShortType int

const (
	OpenLongFlag           = 1  //开多
	CloseLongFlag          = -2 //平多
	OpenShortFlag          = -1 //开空
	CloseShortFlag         = 2  //平空
	OpenLongCloseShortFlag = 4  //开多平空
	OpenShortCloseLongFlag = -4 //开空平多
	CloseShortOpenLongFlag = 4  //开多平空
	CloseLongOpenShortFlag = -4 //开空平多
	None                   = 0  // 不确定
)

func (t OpenCloseLongShortType) String() string {
	switch t {
	case OpenLongFlag:
		return "OpenLongFlag"
	case CloseLongFlag:
		return "CloseLongFlag"
	case OpenShortFlag:
		return "OpenShortFlag"
	case CloseShortFlag:
		return "CloseShortFlag"
	case OpenLongCloseShortFlag:
		return "OpenLongCloseShortFlag"
	case OpenShortCloseLongFlag:
		return "OpenShortCloseLongFlag"
	default:
		return "None"
	}
}
func (t OpenCloseLongShortType) StringCn() string {
	switch t {
	case OpenLongFlag:
		return "开多"
	case CloseLongFlag:
		return "平多"
	case OpenShortFlag:
		return "开空"
	case CloseShortFlag:
		return "平空"
	case OpenLongCloseShortFlag:
		return "平空开多"
	case OpenShortCloseLongFlag:
		return "平多开空"
	default:
		return "None"
	}
}
